import random
import time
import win32api
import win32con

class SwitchLine:
    left, top, right, bottom = [0, 0, 0, 0];
    hwnd = -1
    currentLine = -1
    def __init__(self, left, top, right, bottom, hwnd):
        self.left = left if (left >= 0) else 0
        self.top = top if (top >= 0) else 0
        self.right = right if (right <= 1800) else 1800
        self.bottom = bottom if bottom <= 1000 else 1000
        self.hwnd = hwnd
    def switch(self, num):

        long_position = win32api.MAKELONG(822  + int(self.rand() * 100), 120 + int(self.rand() * 40))#模拟鼠标指针 传送到指定坐标
        win32api.SendMessage(self.hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position)#模拟鼠标按下
        time.sleep(0.2 + self.rand())
        win32api.SendMessage(self.hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position)#模拟鼠标弹起
        time.sleep(0.2 + self.rand())

        long_position = win32api.MAKELONG(750 + int(self.rand() * 70) , 151 + int(self.rand() * 50 + num * 50))#模拟鼠标指针 传送到指定坐标
        win32api.SendMessage(self.hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position)#模拟鼠标按下
        time.sleep(0.2 + self.rand())
        win32api.SendMessage(self.hwnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position)#模拟鼠标弹起
        time.sleep(0.2 + self.rand())
        time.sleep(1)

    def rand(self):
        return random.random()  / 10.0
